package com.test.vcharts.controller;

import com.test.vcharts.task.KLineTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin
public class StockController {
    @Autowired
    private KLineTask kLineTask;
    private final static Logger LOGGER = LoggerFactory.getLogger(StockController.class);



    @SubscribeMapping("/topic/list")
    public Object sub() {
        LOGGER.debug("订阅");
        return 1;
    }

    @RequestMapping("/sub/{stockCode}/{period}")
    @ResponseBody
    public Object subKline( @PathVariable("period") Integer period, @PathVariable("stockCode")String stockCode){
        try {
            kLineTask.run(period,  stockCode);
//            kLineTask.run(5,  "sz002594");
            return "success";
        }catch (Exception e){
            e.printStackTrace();
        }
        return "fail";
    }

}
